<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/5/3
 * Time: 16:14
 */

namespace frontend\models;


class Goods extends \common\models\Goods
{
    public function rules()
    {
        return array_merge(parent::rules(), [

        ]);
    }

    public function scenarios()
    {
        return array_merge(parent::scenarios(), [

        ]);
    }

    public function attributeLabels()
    {
        return array_merge(parent::attributeLabels(), [

        ]);
    }

    /****************************** 以下为公共显示条件的方法 ******************************/

    public function search()
    {
        $this->setSearchParams();
        return self::find()
            ->filterWhere([
                'goods.state' => $this->state,
            ])
            ->andFilterWhere(['like', 'goods.goods_name', $this->goods_name])
            ->andTableSearch()
            ;
    }

    /****************************** 以下为字段的映射方法和格式化方法 ******************************/
    // Map method of field `state`
    public static function getStateMap($prepend = false)
    {
        $map = [
            self::STATE_YES => '开启',
            self::STATE_NO => '关闭',
        ];

        return self::resetMap($map, $prepend);
    }

    // Format method of field `state`
    public function getStateValue($value = null)
    {
        return $this->resetValue($value);
    }

    // Map method of field `op_state`
    public static function getCateIdMap($prepend = false)
    {
        $query = GoodsCate::find();
        $map = $query->map('id', 'name');

        return self::resetMap($map, $prepend);
    }

    // Format method of field `op_state`
    public function getCateIdValue($value = null)
    {
        return $this->resetValue($value);
    }

    //获取首页6个上架的商品
    public static function getIndexGoods()
    {
        return self::find()->where(['state' => self::STATE_YES, "cate_id" => 1])->limit(6)->orderBy('sort ASC')->all();
    }
}